/*
 * @Description: 
 * @Autor: wanghuan
 * @Date: 2021-11-26 11:45:48
 * @LastEditors: wanghuan
 * @LastEditTime: 2021-11-26 13:43:54
 */
// 工具栏默认提示
const tipDefaultConfig = {
    "ql-bold": "加粗",
    "ql-color": "颜色",
    "ql-font": "字体",
    "ql-code": "插入代码",
    "ql-italic": "斜体",
    "ql-link": "添加链接",
    "ql-background": "背景颜色",
    "ql-size": "字体大小",
    "ql-strike": "删除线",
    "ql-script": "上标/下标",
    "ql-underline": "下划线",
    "ql-blockquote": "引用",
    "ql-header": "标题",
    "ql-indent": "缩进",
    "ql-list": "列表",
    "ql-align": "文本对齐",
    "ql-direction": "文本方向",
    "ql-code-block": "代码块",
    "ql-formula": "公式",
    "ql-image": "图片",
    "ql-video": "视频",
    "ql-clean": "清除字体样式",
    "ql-upload": "文件",
};

export default {
    /**
     * @description: 添加工具栏提示
     * @param {*Event} event // 在 ready事件的event对象 
     * @param {Object} otherConfig //其他工具栏提示配置 会覆盖默认配置
     * @return {void}
     */
    addToolTips(event, otherConfig) {
        const oToolBar = event.container.previousElementSibling;
        const aButton = oToolBar.getElementsByTagName("button");
        const aSelect = oToolBar.getElementsByTagName("select");
        const tipConfig = Object.assign({}, tipDefaultConfig, otherConfig);
        Array.prototype.forEach.call(aButton, function (item) {
            if (item.className === "ql-script") {
                item.value === "sub" ?
                    (item.title = "下标") :
                    (item.title = "上标");
            } else if (item.className === "ql-indent") {
                item.value === "+1" ?
                    (item.title = "向右缩进") :
                    (item.title = "向左缩进");
            } else {
                item.title = tipConfig[item.classList[0]];
            }
        });
        Array.prototype.forEach.call(aSelect, function (item) {
            item.parentNode.title = tipConfig[item.classList[0]];
        });
    },
    options: {
        modules: {
            toolbar: [
                ["bold", "italic", "underline", "strike"], //加粗，斜体，下划线，删除线
                ["blockquote", "code-block"], //引用，代码块
                [{
                    header: 1
                }, {
                    header: 2
                }], // 标题，键值对的形式；1、2表示字体大小
                [{
                    list: "ordered"
                }, {
                    list: "bullet"
                }], //列表
                [{
                    script: "sub"
                }, {
                    script: "super"
                }], // 上下标
                [{
                    indent: "-1"
                }, {
                    indent: "+1"
                }], // 缩进
                [{
                    direction: "rtl"
                }], // 文本方向
                [{
                    size: ["small", false, "large", "huge"]
                }], // 字体大小
                [{
                    header: [1, 2, 3, 4, 5, 6, false]
                }], //几级标题
                [{
                    color: []
                }, {
                    background: []
                }], // 字体颜色，字体背景颜色
                [{
                    font: []
                }], //字体
                [{
                    align: []
                }], //对齐方式
                ["clean"], //清除字体样式
                ["image", "video"], //上传图片、上传视频
            ],
        },
        placeholder: "请编辑内容..."
    }
}